package com.qk.management.controller;

import com.qk.common.PageResult;
import com.qk.common.Result;
import com.qk.common.constant.ClueStatusConstants;
import com.qk.domain.clue.ClueDO;
import com.qk.domain.clue.CluesPoolDO;
import com.qk.dto.clue.*;
import com.qk.entity.Clue;
import com.qk.management.aop.anno.LogAnno;
import com.qk.management.service.ClueService;
import com.qk.vo.clue.ClueVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;

/**
 * @author: byLengs
 * @Date: 2025/10/13 17:41
 * @Description:
 */
@Slf4j
@RestController
@SuppressWarnings("all")
@RequestMapping("/clues")
public class ClueController {

    @Autowired
    private ClueService clueService;

    @GetMapping("/pool")
    public Result cluesPoolList(CluesPoolDTO dto){
        PageResult<CluesPoolDO> result = clueService.cluesPoolList(dto);
        return Result.success(result);
    }


    @PutMapping("/false/{id}")
    public Result toFalseClue(@PathVariable Integer id, @RequestBody FalseClueDTO dto){
        clueService.toFalseClue(id, dto);
        return Result.success();
    }

    @LogAnno
    @PutMapping("/toBusiness/{id}")
    public Result toBusiness(@PathVariable Integer id) {
        clueService.toBusiness(id);
        return Result.success();
    }

    @LogAnno
    @PutMapping
    public Result updateClueInfoById(@RequestBody UpdateClueInfoDTO dto) {
        clueService.updateClueInfoById(dto);
        return Result.success();
    }


    @GetMapping("/{id}")
    public Result getClueInfoById(@PathVariable Integer id) {
        ClueVO clue = clueService.getClueInfoById(id);
        return Result.success(clue);
    }

    @LogAnno
    @PutMapping("/assign/{clueId}/{userId}")
    public Result assignClue(@PathVariable Integer clueId, @PathVariable Integer userId) {
        clueService.updateById(Clue.builder()
                .id(clueId)
                .userId(userId)
                .status(ClueStatusConstants.WAIT_FOLLOW_UP)
                .updateTime(LocalDateTime.now())
                .build());
        return Result.success();
    }


    @GetMapping
    public Result getByList(ClueListDto dto) {
        PageResult<ClueDO> result = clueService.getByList(dto);
        return Result.success(result);
    }


    @LogAnno
    @PostMapping
    public Result addClue(@RequestBody ClueDTO dto) {
        clueService.addClue(dto);
        return Result.success();
    }
}
